package com.fjnu;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @desc:
 * @author:
 * @date:
 */

@Configuration
@ComponentScan(basePackages = "com.fjnu")
@PropertySource("db.properties")
@Slf4j
public class SpringConfig {
    @Value("${mysql.driver}")
    private String driver ;
    @Value("${mysql.url}")
    private String url ;
    @Value("${mysql.username}")
    private String username ;
    @Value("${mysql.password}")
    private String password ;
    @Bean
    public Connection connection() {
        try {
            Class.forName(driver);
            return DriverManager.getConnection(url, username, password);

        } catch (Exception e) {
            log.error("数据库连接失败", e);
        }
        return null ;
    }

}
